export default ({
  namespaced: true,
  state: {
    //用于存储当前登录名称,刷新后初始化时从sessionStorage中加载
    // user:JSON.parse(sessionStorage.getItem('user')),
    // 登录状态
    loginStatus: false,
    // token
    token: null,
    // 用户信息:用户头像,用户昵称
    userInfo: {},
    // 用户获取头像的url
    urlSrcDefaul: '/img/000.jpg',
    urlSrcAdd: 'http://localhost:3000/',
  },
  getters: {
  },
  mutations: {
    // 声明一个方法,在该方法中修改state.user用户名
    // 该方法不是用户直接调用,由Vuex来管理,Vuex会在调用该方法时传入两个参数:state对象,用户自定义数据
    //在此使用state payload接收参数
    updateUserInfo(state, payload) {
      console.log(24)

      state.loginStatus = true
      state.token = payload.token
      state.userInfo = payload
      // state.user=payload
      // 修改用户信息时,将用户名存入sessionStorage
      // window.sessionStorage.setItem('user',JSON.stringify(payload))
      window.sessionStorage.setItem('userIn', JSON.stringify(payload))
      window.sessionStorage.setItem('loginStatus', true)
      window.sessionStorage.setItem('urlSrcDefaul', '/img/000.jpg')
      window.sessionStorage.setItem('urlSrcAdd', 'http://localhost:3000/')
    },
    getUserIn(state, data) {
      let userInfo = JSON.parse(sessionStorage.getItem('userIn'))
      if (userInfo) {
        state.token = userInfo.token
        state.userInfo = userInfo
        state.loginStatus = true
      }
    },
    logout(state) {
      // state.user=''
      state.userInfo = ''
      state.loginStatus = false
      window.sessionStorage.removeItem('loginStatus')
      window.sessionStorage.removeItem('userIn')
      window.sessionStorage.removeItem('urlSrcDefaul')
      window.sessionStorage.removeItem('urlSrcAdd')
    },
    updateOnceProperty(state, obj) {
      let ori = JSON.parse(sessionStorage.getItem('userIn'))
      ori[obj.key] = obj.value
      sessionStorage.setItem('userIn', JSON.stringify(ori))
      state.userInfo = ori
    }
  },
  actions: {
  },
  modules: {
  }
})